package com.studyshare.model;

import com.studyshare.modelBD.PersonneBD;

public class Personne {

	public String login;
	public String mail;
	public String mdp;
	public String prenom;
	public String nom;
	public int nbPoint;
	public int nbCredit;
	public String photo;
	
	public Personne(String login, String mail, String mdp, String nom,
			 String prenom, int nbPoint, int nbCredit, String photo) {
		super();
		this.login = login;
		this.mail = mail;
		this.mdp = mdp;
		this.nom = nom;
		this.prenom = prenom;
		this.nbPoint = nbPoint;
		this.nbCredit = nbCredit;
		this.photo = photo;
	}
	
	public Personne() {
		// TODO Auto-generated constructor stub
	}

	public static Boolean connexion (String login, String pass, PersonneBD personneBD){
		personneBD.open();
		if(personneBD.verifPersonne(login, pass) != null){
			personneBD.close();
			return true;
		}
		personneBD.close();
		return false;
		
	}

	public static Boolean loginExiste (String login, PersonneBD personneBD){
		personneBD.open();
		if(personneBD.trouvePersonne(login) != null){
			personneBD.close();
			return true;
		}
		personneBD.close();
		return false;
		
	}

	public static Boolean creerCompte (String login, String mail, String mdp, PersonneBD personneBD){
		personneBD.open();
		if(personneBD.creerPersonne(login, mail, mdp) != -1){
			personneBD.close();
			return true;
		}
		personneBD.close();
		return false;
	}
	/*
	public static Boolean ajouterLangueParlee (String login, String langue, PersonneBD personneBD){
		personneBD.open();
		if(personneBD.ajouterLangue(login, langue) != -1){
			personneBD.close();
			return true;
		}
		personneBD.close();
		return false;
	}

	public static Boolean ajouterMatiereMaitrisee (String login, String matiere, PersonneBD personneBD){
		personneBD.open();
		if(personneBD.ajouterMatiere(login, matiere) != -1){
			personneBD.close();
			return true;
		}
		personneBD.close();
		return false;
	}
	*/
	
	
	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getMdp() {
		return mdp;
	}

	public void setMdp(String mdp) {
		this.mdp = mdp;
	}

	public String getPrenom() {
		return prenom;
	}

	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}
	
	public static boolean isBetween(int x, int lower, int upper) {
		  return lower <= x && x <= upper;
	}
	
	public int getGrade() {
		if(isBetween(getNbPoint(), 0, 9))			
			return 0;
		if(isBetween(getNbPoint(), 10, 149))			
			return 1;
		if(isBetween(getNbPoint(), 150, 299))			
			return 2;
		if(isBetween(getNbPoint(), 300, 499))			
			return 3;
		return 4;
	}
	
	public int getNbPoint() {
		return nbPoint;
	}

	public void setNbPoint(int nbPoint) {
		this.nbPoint = nbPoint;
	}

	public int getNbCredit() {
		return nbCredit;
	}

	public void setNbCredit(int nbCredit) {
		this.nbCredit = nbCredit;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}	
	
}
